package com.example.service.helper;

import com.example.DTO.FLTaskResultDTO;
import com.example.entity.FLTrainingRound;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: FLTrainingRoundConverter
 * Package: com.example.service.helper
 * Description:
 *
 * @Author achb
 * @Create 2025/3/30 17:44
 * @Version 1.0
 */
public class FLTrainingRoundConverter {
    public static List<FLTrainingRound> convertFromTaskResult(FLTaskResultDTO taskResult) {
        List<FLTrainingRound> rounds = new ArrayList<>();
        int batchSize = taskResult.getParameters().getDataset().getBatch_size();

        for (int i = 0; i < taskResult.getResults().getRounds().size(); i++) {
            FLTrainingRound round = new FLTrainingRound();
            round.setTaskId(taskResult.getTask_id());
            round.setBatchSize(batchSize);
            round.setRoundNumber(taskResult.getResults().getRounds().get(i));
            round.setTrainAcc(taskResult.getResults().getTrain_acc().get(i));
            round.setTestAcc(taskResult.getResults().getTest_acc().get(i));
            round.setEndTime(LocalDateTime.now()); // 根据实际情况设置时间
            rounds.add(round);
        }
        return rounds;
    }
}

